package com.data.modules.online.cgform.util;

import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
import java.util.Map;

import com.data.modules.online.cgform.entity.OnlCgformField;

public class OnlineDbHandler {

    public static final String f328a = "int";

    public static final String f329b = "Integer";

    public static final String f330c = "double";

    public static final String f331d = "BigDecimal";

    public static final String f332e = "Blob";

    public static final String f333f = "Date";

    public static final String f334g = "datetime";

    public static final String f335h = "Timestamp";

    public static boolean isNumberType(String str) {
        return "int".equals(str) || "double".equals(str) || "BigDecimal".equals(str) || "Integer".equals(str);
    }

    public static boolean isDateType(String str) {
        return "Date".equalsIgnoreCase(str) || "datetime".equalsIgnoreCase(str) || f335h.equalsIgnoreCase(str);
    }

    public static String createDbField(String str, OnlCgformField onlCgformField, JSONObject jSONObject, Map<String, Object> map) {
        String dbType = onlCgformField.getDbType();
        String dbFieldName = onlCgformField.getDbFieldName();
        String fieldShowType = onlCgformField.getFieldShowType();
        if (jSONObject.get(dbFieldName) == null) {
            return "null";
        }
        if ("int".equals(dbType)) {
            map.put(dbFieldName, Integer.valueOf(jSONObject.getIntValue(dbFieldName)));
            return "#{" + dbFieldName + ",jdbcType=INTEGER}";
        } else if ("double".equals(dbType)) {
            map.put(dbFieldName, Double.valueOf(jSONObject.getDoubleValue(dbFieldName)));
            return "#{" + dbFieldName + ",jdbcType=DOUBLE}";
        } else if ("BigDecimal".equals(dbType)) {
            map.put(dbFieldName, new BigDecimal(jSONObject.getString(dbFieldName)));
            return "#{" + dbFieldName + ",jdbcType=DECIMAL}";
        } else if ("Blob".equals(dbType)) {
            map.put(dbFieldName, jSONObject.getString(dbFieldName) != null ? jSONObject.getString(dbFieldName).getBytes() : null);
            return "#{" + dbFieldName + ",jdbcType=BLOB}";
        } else if ("Date".equals(dbType)) {
            String string = jSONObject.getString(dbFieldName);
            if ("ORACLE".equals(str)) {
                if (OnlFormShowType.f320d.equals(fieldShowType)) {
                    if (string.length() > 10) {
                        string = string.substring(0, 10);
                    }
                    map.put(dbFieldName, string);
                    return "to_date(#{" + dbFieldName + "},'yyyy-MM-dd')";
                }
                if (string.length() == 10) {
                    string = jSONObject.getString(dbFieldName) + " 00:00:00";
                }
                map.put(dbFieldName, string);
                return "to_date(#{" + dbFieldName + "},'yyyy-MM-dd HH24:mi:ss')";
            } else if (!"POSTGRESQL".equals(str)) {
                map.put(dbFieldName, jSONObject.getString(dbFieldName));
                return "#{" + dbFieldName + "}";
            } else if (OnlFormShowType.f320d.equals(fieldShowType)) {
                if (string.length() > 10) {
                    string = string.substring(0, 10);
                }
                map.put(dbFieldName, string);
                return "CAST(#{" + dbFieldName + "} as TIMESTAMP)";
            } else {
                if (string.length() == 10) {
                    string = jSONObject.getString(dbFieldName) + " 00:00:00";
                }
                map.put(dbFieldName, string);
                return "CAST(#{" + dbFieldName + "} as TIMESTAMP)";
            }
        } else {
            map.put(dbFieldName, jSONObject.getString(dbFieldName));
            return "#{" + dbFieldName + ",jdbcType=VARCHAR}";
        }
    }
}
